public class ShellSort2 {
    static void shellsSort(int arr[], int len) {
        int d, i, j, temp;
        for (d = len / 2; d >= 1; d /= 2) {
            // 这里类似直接插入排序
            for (i = d; i < len; i++) {
                temp = arr[i];
                for (j = i - d; j >= 0 && temp < arr[j]; j -= d) {
                    arr[j + d] = arr[j];
                }
                arr[j + d] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr={9,8,7,6,5,4,3,2,1};
        shellsSort(arr, arr.length);
        for (int x :
                arr) {
            System.out.println(x);
        }

    }
}
